package com.lab.web.controller.biz;

import com.lab.common.annotation.Log;
import com.lab.common.core.controller.BaseController;
import com.lab.common.core.domain.AjaxResult;
import com.lab.common.core.domain.entity.SysRole;
import com.lab.common.core.domain.model.LoginUser;
import com.lab.common.core.page.TableDataInfo;
import com.lab.common.enums.BusinessType;
import com.lab.common.utils.poi.ExcelUtil;
import com.lab.system.domain.AppointmentViolationRecord;
import com.lab.system.domain.Lab;
import com.lab.system.service.IAppointmentViolationRecordService;
import com.lab.system.service.ILabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户违规记录Controller
 *
 * @author cf
 * @date 2025-02-11
 */
@RestController
@RequestMapping("/biz/appointment")
public class AppointmentViolationRecordController extends BaseController {
    @Autowired
    private IAppointmentViolationRecordService appointmentViolationRecordService;
    @Autowired
    private ILabService labService;

    /**
     * 查询用户违规记录列表
     */
    @PreAuthorize("@ss.hasPermi('biz:appointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppointmentViolationRecord appointmentViolationRecord) {
        LoginUser loginUser = getLoginUser();
        startPage();

        List<AppointmentViolationRecord> list = appointmentViolationRecordService.selectAppointmentViolationRecordList(appointmentViolationRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户违规记录列表
     */
    @PreAuthorize("@ss.hasPermi('biz:appointment:export')")
    @Log(title = "用户违规记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppointmentViolationRecord appointmentViolationRecord) {
        List<AppointmentViolationRecord> list = appointmentViolationRecordService.selectAppointmentViolationRecordList(appointmentViolationRecord);
        ExcelUtil<AppointmentViolationRecord> util = new ExcelUtil<AppointmentViolationRecord>(AppointmentViolationRecord.class);
        util.exportExcel(response, list, "用户违规记录数据");
    }

    /**
     * 获取用户违规记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:appointment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appointmentViolationRecordService.selectAppointmentViolationRecordById(id));
    }

    /**
     * 新增用户违规记录
     */
    @PreAuthorize("@ss.hasPermi('biz:appointment:add')")
    @Log(title = "用户违规记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppointmentViolationRecord appointmentViolationRecord) {
        return toAjax(appointmentViolationRecordService.insertAppointmentViolationRecord(appointmentViolationRecord));
    }

    /**
     * 修改用户违规记录
     */
    @PreAuthorize("@ss.hasPermi('biz:appointment:edit')")
    @Log(title = "用户违规记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppointmentViolationRecord appointmentViolationRecord) {
        return toAjax(appointmentViolationRecordService.updateAppointmentViolationRecord(appointmentViolationRecord));
    }

    /**
     * 删除用户违规记录
     */
    @PreAuthorize("@ss.hasPermi('biz:appointment:remove')")
    @Log(title = "用户违规记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appointmentViolationRecordService.deleteAppointmentViolationRecordByIds(ids));
    }
}
